package com.gec.hawaste.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.hawaste.entity.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gec.hawaste.entity.SysRoleDo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author gec
 * @since 2022-11-23
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {
    @Select("SELECT\n" +
            "\tsr.*,\n" +
            "\tso.NAME office_name \n" +
            "FROM\n" +
            "\tsys_role sr,\n" +
            "\tsys_office so " +
            " ${ew.customSqlSegment}")
    IPage<SysRoleDo> selectByCondition(IPage<SysRoleDo> page, Wrapper ew);


    @Select("select sr.*, " +
            "so.name office_name " +
            "from " +
            "sys_role sr, " +
            "sys_office so " +
            "where " +
            "sr.del_flag=0 " +
            "and so.del_flag=0 " +
            "and sr.office_id=so.id " +
            "and sr.id=#{rid} ")
    SysRoleDo selectByRid(Long id);


    @Select("SELECT    \n" +
            "    sr.*  \n" +
            "FROM \n" +
            "    sys_user su,\n" +
            "    sys_user_role sur, \n" +
            "    sys_role sr  \n" +
            "WHERE  su.id = sur.user_id  \n" +
            "    AND sur.role_id = sr.id  \n" +
            "    AND su.id = #{uid}\n" +
            "    AND su.del_flag = 0 \n" +
            "    AND sur.del_flag = 0 \n" +
            "    AND sr.del_flag = 0 ")
    List<SysRole> selectByUid(Long uid);
}
